var express = require('express');
var router = express.Router();
const fs = require('fs')

let { storeModel } = require('../model/model');
//获取所有药店信息
router.get('/storelist', async (req, res) => {
  let list = await storeModel.find();
  res.send({
    code: 200,
    list
  })
})

//获取所有会议列表
router.get('/meetlist', async (req, res) => {
  let list = JSON.parse(fs.readFileSync('./data/meet.json'))
  res.send({
    data: list
  })
})


//添加会议
router.post('/addmeet', async (req, res) => {
  let list = JSON.parse(fs.readFileSync('./data/meet.json'))
  let id = list.length + 1
  let { name, date, dateTime, address, tel, description } = req.body
  list.push({
    id,
    title: name,
    date,
    time: dateTime,
    address,
    tel,
    description,
    state: "open"
  })
  fs.writeFileSync("./data/meet.json", JSON.stringify(list))
  res.send({
    code: 200,
    msg: "添加成功"
  })
})


module.exports = router;
